//
//  ViewController.m
//  8.Animations
//
//  Created by iD Student on 7/8/13.
//  Copyright (c) 2013 iD Student. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    imageArray1 = [[NSMutableArray alloc]init];
    imageArray2 = [[NSMutableArray alloc]init];
    for(int i = 1; i < 166; i++)
    {
        if (i < 10) {
            [imageArray1 insertObject:[UIImage imageNamed:[NSString stringWithFormat:@"00%i.jpg", i]] atIndex:(i-1)];
        }
        else if (i >= 10 && i < 100)
        {
            [imageArray1 insertObject:[UIImage imageNamed:[NSString stringWithFormat:@"0%i.jpg", i]] atIndex:(i-1)];
        }
        else {
            [imageArray1 insertObject:[UIImage imageNamed:[NSString stringWithFormat:@"%i.jpg", i]] atIndex:(i-1)];
        }
    }
    for (int i = 166; i < 199; i++) {
        [imageArray2 insertObject:[UIImage imageNamed:[NSString stringWithFormat:@"%i.jpg", i]] atIndex:(i-166)];
    }
    animatedImage1.animationImages = imageArray1;
    animatedImage1.animationDuration = 8;
    animatedImage1.animationRepeatCount = 1;
    [animatedImage1 startAnimating];
    checkTimer = [NSTimer scheduledTimerWithTimeInterval:.01 target:self selector:@selector(animationHasEnded) userInfo:nil repeats:TRUE];
}

- (void)animationHasEnded
{
    if(animatedImage1.isAnimating == false)
    {
    animatedImage1.animationImages = imageArray2;
    animatedImage1.animationDuration = 3;
    animatedImage1.animationRepeatCount = 20;
    [animatedImage1 startAnimating];
        [checkTimer invalidate];
    }
    else {
        
    }
    
    

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
